package org.example.system.service;

import org.example.system.entity.User;
import org.example.system.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;

    public User findByUsername(String username) {
        List<User> list = userMapper.selectByUsername(username);
        return list != null && !list.isEmpty() ? list.get(0) : null;
    }

    public int add(User user) {
        return userMapper.insert(user);
    }

    public java.util.List<User> findAll() {
        return userMapper.selectAll();
    }

    public int update(User user) {
        return userMapper.update(user);
    }

    public int delete(Long id) {
        return userMapper.deleteById(id);
    }

    public User findById(Long id) {
        return userMapper.selectById(id);
    }

    // 其他用户相关业务方法可在此扩展
} 